package com.project.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.project.bean.GymBean;
import com.project.bean.PageBean;
import com.project.dao.GymMapper;
import com.project.service.IGymService;
@Service
public class GymServiceImpl implements IGymService {
	@Autowired
	private GymMapper gymdao;

	@Override
	public GymBean findGymById(int id) {
		GymBean gym = gymdao.selectByPrimaryKey(id);
		return gym;
	}

	@Override
	public List<GymBean> findAllGym() {
		List<GymBean> list = gymdao.findAll();
		return list;
	}

	@Override
	public PageBean findGymByPage(int page, int size) {
		PageBean bean = new PageBean();
		List<GymBean> list = gymdao.findByPage((page-1)*size, size);
		int number = gymdao.findAllNumber();
		int totalPage = (number%size==0)?(number/size):(number/size+1);
		bean.setList(list);
		bean.setPage(page);
		bean.setSize(size);
		bean.setTotalPage(totalPage);
		bean.setTotalNumber(number);
		return bean;
	}

	@Override
	public int updateGymInfo(GymBean gym) {
		int result = gymdao.updateByPrimaryKeySelective(gym);
		return result;
	}
	
	@Override
	public int addGymGUId(int cuid) {
		return gymdao.addGymGUId(cuid);
	}
	@Override
	public int updateGymMessage(int id, String message) {
		
		return gymdao.updateGymMessage(id, message);
	}

}
